package com.example.siyun.controller.coursecontrooller;

import com.example.siyun.pojo.CourseTree;
import com.example.siyun.service.impl.courseserviceimpl.CourseServiceImpl;
import com.example.siyun.util.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
/**
 * @Auther: 全
 * @Date: 2022/9/26 09:33
 * @Description: 课程的控制层
 */
@Slf4j
@RestController
public class CourseController {
    @Autowired
    private CourseServiceImpl courseService;
    /**
     * 获取课程左侧树形结构
     * @ruturn 返回查询出来的树形数据
     */
    @RequestMapping("/intermediate/gettree")
    public Map<String, Object> getTree() {
        log.info("获取课程的树形结构的信息");
        Map<String, Object> map = new HashMap<>();
        log.info("获取课程的树形结构信息成功");
        map.put("menulists", courseService.findTree());
        return map;
    }
    /**
     * 删除子节点的所有数据
     * @param id 要删除的要删除节点的id
     */
    @RequestMapping("/primary/del")
    public PageResult del(int id) {
        log.info("删除课程树形结构的数据");
        courseService.delAll(id);
        PageResult pageResult=new PageResult();
        pageResult.setMessage("成功");
        log.info("删除课程树形结构的数据成功");
        return pageResult;
    }


    /**
     * 添加树形信息
     * @param coursetree 要添加的信息
     */
    @RequestMapping("/advanced/addtree")
    public PageResult addTree(CourseTree coursetree) {
        courseService.addTree(coursetree);
        Map<String, Object> map = new HashMap<>();
        PageResult pageResult=new PageResult();
        pageResult.setMessage("成功");
        return pageResult;
    }
    /**
     * 修改树形信息
     * @param coursetree 要修改的信息
     */
    @RequestMapping("/advanced/edittree")
    public PageResult editTree1(CourseTree coursetree) {
        courseService.editTree(coursetree);
        PageResult pageResult=new PageResult();
        pageResult.setMessage("成功");
        return pageResult;
    }
}
